const expressJSDocSwagger = require("express-jsdoc-swagger");
const { HOST, PORT, BASE_PATH, DOCS_PATH } = process.env;
const options = {
  info: {
    version: "1.0.0",
    title: "In YanCheng API 接口",
    description: "In YanCheng API 接口（DEV）",
    license: {
      name: "MIT",
    },
  },
  // security: {
  //   BearerAuth: {
  //     type: "http",
  //     scheme: "bearer",
  //   },
  // },
  tags: [{ name: "users", description: "用户管理" }],
  servers: [
    {
      url: "http://{HOST}:{PORT}/{BASE_PATH}",
      description: "DEV API server",
      variables: {
        HOST: {
          default: HOST,
        },
        PORT: {
          enum: [PORT],
          default: PORT,
        },
        BASE_PATH: {
          default: BASE_PATH.slice(1),
        },
      },
    },
  ],
  //   security: {
  //     BasicAuth: {
  //       type: "http",
  //       scheme: "basic",
  //     },
  //   },
  // Base directory which we use to locate your JSDOC files
  baseDir: __dirname,
  // Glob pattern to find your jsdoc files (multiple patterns can be added in an array)
  filesPattern: "../routes/**/*.js",
  // URL where SwaggerUI will be rendered
  swaggerUIPath: `${BASE_PATH}${DOCS_PATH}`,
  // Expose OpenAPI UI
  exposeSwaggerUI: true,
  // Expose Open API JSON Docs documentation in `apiDocsPath` path.
  exposeApiDocs: false,
  // Open API JSON Docs endpoint.
  // apiDocsPath: "/v1/swagger",
  // Set non-required fields as nullable by default
  notRequiredAsNullable: false,
  // You can customize your UI options.
  // you can extend swagger-ui-express config. You can checkout an example of this
  // in the `example/configuration/swaggerOptions.js`
  swaggerUiOptions: {},
  // multiple option in case you want more that one instance
  multiple: true,
};

module.exports = (app) => expressJSDocSwagger(app)(options);
